package entities;

import org.newdawn.slick.SlickException;

import sound.SoundManager;
import util.Vector2D;

public class SimpleWeapon extends Weapon {

	private long lastShotTime;

	public SimpleWeapon(String shotSprite, int damage, Entity owner, int timeout) {
		super(shotSprite, damage, owner, timeout);
	}

	@Override
	public void shoot(Vector2D velocity) {
		if (System.currentTimeMillis() - lastShotTime >= timeout) {
			try {
				Shot shot = new Shot(shotSprite, owner, damage, velocity);
				shot.spawn(owner.level, owner.center());
				if (owner == owner.level.getPlayer()) {
					SoundManager.getSoundManager().playSound(SoundManager.simpleShot, 3f);
				}
//				System.out.printf("Shot spawned: owner=%s, pos=(%f/%f), velocity=(%f/%f)\n", owner.getName(), owner.center().getX(), owner.center().getY(), velocity.getX(), velocity.getY());
			} catch (SlickException e) {
				e.printStackTrace();
			}
			lastShotTime = System.currentTimeMillis();
		}

	}

}
